package com.mhz.echartsdemo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.mhz.echartsdemo.pojo.StatisticsDaily;
import com.mhz.echartsdemo.mapper.StatisticsDailyMapper;
import com.mhz.echartsdemo.service.StatisticsDailyService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 网站统计日数据 服务实现类
 * </p>
 *
 * @author mhz
 * @since 2021-03-30
 */
@Service
public class StatisticsDailyServiceImpl extends ServiceImpl<StatisticsDailyMapper, StatisticsDaily> implements StatisticsDailyService {


    @Override
    public Map<String, Object> getChartData() {
        QueryWrapper<StatisticsDaily> dayQueryWrapper = new QueryWrapper<>();
        dayQueryWrapper.select("login_num", "date_calculated");
        List<StatisticsDaily> dayList = baseMapper.selectList(dayQueryWrapper);
        List<String> calculatedList = new ArrayList<>();
        List<Integer> numDateList = new ArrayList<>();

        for (StatisticsDaily daily : dayList) {
            calculatedList.add(daily.getDateCalculated());
            numDateList.add(daily.getLoginNum());
        }
        Map<String, Object> map = new HashMap<>();
        map.put("calculatedList", calculatedList);
        map.put("numDateList", numDateList);
        return map;
    }

    @Override
    public Map<String, Object> getChartDataVideo() {
        QueryWrapper<StatisticsDaily> dayQueryWrapper = new QueryWrapper<>();
        dayQueryWrapper.select("video_view_num", "date_calculated");
        List<StatisticsDaily> dayList = baseMapper.selectList(dayQueryWrapper);
        List<String> calculatedList = new ArrayList<>();
        List<Integer> numDateList = new ArrayList<>();

        for (StatisticsDaily daily : dayList) {
            calculatedList.add(daily.getDateCalculated());
            numDateList.add(daily.getVideoViewNum());
        }
        Map<String, Object> map = new HashMap<>();
        map.put("calculatedList", calculatedList);
        map.put("numDateList", numDateList);
        return map;
    }

    @Override
    public Map<String, Object> getChartDataCouse() {
        QueryWrapper<StatisticsDaily> dayQueryWrapper = new QueryWrapper<>();
        dayQueryWrapper.select("course_num", "date_calculated");
        List<StatisticsDaily> dayList = baseMapper.selectList(dayQueryWrapper);
        List<String> calculatedList = new ArrayList<>();
        List<Integer> numDateList = new ArrayList<>();

        for (StatisticsDaily daily : dayList) {
            calculatedList.add(daily.getDateCalculated());
            numDateList.add(daily.getCourseNum());
        }
        Map<String, Object> map = new HashMap<>();
        map.put("calculatedList", calculatedList);
        map.put("numDateList", numDateList);
        return map;
    }

    @Override
    public Map<String, Object> getChartDataRegister() {
        QueryWrapper<StatisticsDaily> dayQueryWrapper = new QueryWrapper<>();
        dayQueryWrapper.select("register_num", "date_calculated");
        List<StatisticsDaily> dayList = baseMapper.selectList(dayQueryWrapper);
        List<String> calculatedList = new ArrayList<>();
        List<Integer> numDateList = new ArrayList<>();

        for (StatisticsDaily daily : dayList) {
            calculatedList.add(daily.getDateCalculated());
            numDateList.add(daily.getRegisterNum());
        }
        Map<String, Object> map = new HashMap<>();
        map.put("calculatedList", calculatedList);
        map.put("numDateList", numDateList);
        return map;
    }
}
